package lol.niconico.libtest.http

import lol.niconico.libtest.entity.UserEntity
import okhttp3.OkHttpClient
import retrofit2.Retrofit
import retrofit2.converter.gson.GsonConverterFactory
import retrofit2.http.GET
import retrofit2.http.Query

/**
 * Created by ZhangQianqian on 2020/7/15  11:05.
 * email 415692689@qq.com
 */
interface GithubService {

    @GET("users")
    suspend fun getGithubAccount(
        @Query("since") id: Int,
        @Query("per_page") perPage: Int
    ): List<UserEntity>

    companion object {
        fun create(): GithubService {
            val client = OkHttpClient.Builder()
                .addInterceptor(LogInterceptor())
                .build()

            val retrofit = Retrofit.Builder()
                .client(client)
                .baseUrl("https://api.github.com/")
                .addConverterFactory(GsonConverterFactory.create())
                .build()

            return retrofit.create(GithubService::class.java)
        }
    }
}